package exam.controller;

import exam.bean.ProjectClassic;
import exam.bean.ProjectLevel;
import exam.service.IProjectClassicService;
import exam.service.impl.ProjectClassicServiceImpl;
import exam.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController()
@RequestMapping("/ProjectClassic")
public class ProjectClassicController {
    @Autowired
    IProjectClassicService projectClassicService;
    @ResponseBody
    @GetMapping("/ProjectClassicAll")
    public Msg ProjectLevelAll(){
        return Msg.success().add("projectClassic",projectClassicService.selectInfo());
    }



    @ResponseBody
    @GetMapping("/detail")
    public Msg detail(@RequestParam(value="id") int id){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("id",id);
        return Msg.success().add("projectLevel",projectClassicService.selectInfoSingle(map));
    }

    @ResponseBody
    @PreAuthorize("hasAuthority('sys:sysParam:projectClass:delete')")
    @GetMapping("/delete")
    public Msg delete(@RequestParam(value="id") int id){
        int re = projectClassicService.deleteInfo(id);

        return re > 0 ? Msg.success().setMessage("删除成功") : Msg.fail().setMessage("删除失败");
    }


    @ResponseBody
    @PostMapping("/update")
    @PreAuthorize("hasAuthority('sys:sysParam:projectClass:update')")
    public Msg paperLevelUpdate(@RequestBody ProjectClassic projectClassic){
        int res = projectClassicService.updateInfo(projectClassic);
        return res > 0 ? Msg.success().setMessage("修改成功") : Msg.fail().setMessage("修改失败");
    }

    @ResponseBody
    @PostMapping("/insert")
    @PreAuthorize("hasAuthority('sys:sysParam:projectClass:add')")
    public Msg projectLevelInsert(@RequestBody  ProjectClassic projectClassic){
        int res = projectClassicService.insertInfo(projectClassic);
        return res > 0 ? Msg.success().setMessage("添加成功") : Msg.fail().setMessage("添加失败");
    }
}
